package cn.hu.org.controller;

import cn.hu.basic.util.AjaxResult;
import cn.hu.basic.util.PageList;
import cn.hu.org.domain.DictionaryType;
import cn.hu.org.query.DictionaryTypeQuery;
import cn.hu.org.service.IDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dictionary_type")
public class DictionaryTypeController {
    @Autowired
    private IDictionaryTypeService dictionaryTypeService;

    @GetMapping("/{id}")
    public DictionaryType findOne(@PathVariable Long id){
        return dictionaryTypeService.findById(id);
    }

    @GetMapping
    public List<DictionaryType> findAll(){
        return dictionaryTypeService.findAll();
    }

    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody DictionaryType dictionaryType){
            if(dictionaryType.getId() == null){
                dictionaryTypeService.add(dictionaryType);
            }else {
                dictionaryTypeService.update(dictionaryType);
            }
            return AjaxResult.getInstance();
    }

    @PostMapping
    public PageList<DictionaryType> getListByQuery(@RequestBody DictionaryTypeQuery query){
        return dictionaryTypeService.listByQuery(query);
    }

    @DeleteMapping("/{id}")
    public AjaxResult deleteDep(@PathVariable Long id){
        dictionaryTypeService.delete(id);
            return AjaxResult.getInstance();
    }

    @PatchMapping
    public AjaxResult patchDelete(@RequestBody List<Long> ids){
        dictionaryTypeService.patchDelete(ids);
            return AjaxResult.getInstance();
    }

}
